package com.ssf.domain.strategy.model.entity;

import com.ssf.types.common.Constants;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Slf4j
public class StrategyRuleEntity {
    /**
     * 抽奖策略ID
     */
    private Integer strategyId;
    /**
     * 奖品id
     */
    private Integer awardId;

    /**
     * 抽奖规则模型【rule_random - 随机值计算、rule_lock - 抽奖几次后解锁、rule_luck_award - 幸运奖(兜底奖品)】
     */
    private String ruleModel;
    /**
     * 抽象规则比值
     */
    private String ruleValue;

    /**
     * 仅对于rule_weight规则适用！！！
     * 将rule_weight规则字符串拆解成Map
     * @return
     */
    public HashMap<Integer, List<Integer>> splitRuleWeights() {
        if(!ruleModel.equals(Constants.RULE_WEIGHT)) {
            log.info("只能对rule_weight规则使用这个方法！");
            return null;
        }
        HashMap<Integer,List<Integer>> result=new HashMap<>();
        String[] splits = ruleValue.split(" ");
        for (String s : splits) {
            String[] split = s.split(":");
            ArrayList<Integer> list=new ArrayList<>();
            for (String string : split[1].split(",")) {
                list.add(Integer.parseInt(string));
            }
            result.put(Integer.parseInt(split[0]),list);
        }
        return result;
    }
}
